package com.c7.servlet;

import com.c7.dan.NewsDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet
public class NewsDeiServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int NewsID = Integer.parseInt(req.getParameter("NewsID"));
        int result =(new NewsDao().delete(NewsID));
        if (result>0){
            resp.sendRedirect("news.jsp");
        }else{
            req.setAttribute("msg", "新闻更新失败");
            req.setAttribute("url","news.jsp");
            req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
        }
    }
}
